package shuai7boy.vip.transform.mr.au;

import java.io.IOException;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.MapWritable;


import shuai7boy.vip.common.GlobalConstants;
import shuai7boy.vip.transform.mr.IOutPutCollector;
import shuai7boy.vip.transformer.model.dim.StatsUserDimension;
import shuai7boy.vip.transformer.model.dim.base.BaseDimension;
import shuai7boy.vip.transformer.model.value.BaseStatsValueWritable;
import shuai7boy.vip.transformer.model.value.reduce.MapWritableValue;
import shuai7boy.vip.transformer.server.IDimensionConverter;

public class ActiveUserCollector implements IOutPutCollector {

	@Override
	public void collector(Configuration conf, BaseDimension key, BaseStatsValueWritable value, PreparedStatement pstmt,
			IDimensionConverter converter) throws IOException, SQLException {
		
		StatsUserDimension statsUserDimension = (StatsUserDimension) key;
		IntWritable intWritable = (IntWritable) (((MapWritableValue) value).getValue()).get(new IntWritable(-1));
		
		int i = 0;
		pstmt.setInt(++i, statsUserDimension.getStatsCommon().getPlatform().getId());
		pstmt.setInt(++i, statsUserDimension.getStatsCommon().getDate().getId());
		pstmt.setInt(++i, intWritable.get());
		pstmt.setString(++i,conf.get(GlobalConstants.RUNNING_DATE_PARAMES));
		pstmt.setInt(++i, intWritable.get());
		//添加入batch中
		pstmt.addBatch();
	}

}
